<?php

/**
 * This is the model class for table "xman_user_academy".
 *
 * The followings are the available columns in table 'xman_user_academy':
 * @property integer $user_academy_id
 * @property integer $user_academy_name_id
 * @property string $user_academy_diploma
 * @property integer $user_academy_speciality_id
 * @property string $user_academy_started_time
 * @property string $user_academy_end_time
 * @property string $user_academy_type_of_training
 * @property string $user_academy_graduation_degree
 * @property integer $user_academy_user_id
 *
 * The followings are the available model relations:
 * @property AcademyName $userAcademyName
 * @property User $userAcademyUser
 * @property Speciality $userAcademySpeciality
 */
class UserAcademy extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return UserAcademy the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_user_academy';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_academy_user_id', 'required'),
			array('user_academy_name_id, user_academy_speciality_id, user_academy_user_id', 'numerical', 'integerOnly'=>true),
			array('user_academy_diploma, user_academy_type_of_training, user_academy_graduation_degree', 'length', 'max'=>100),
			array('user_academy_started_time, user_academy_end_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_academy_id, user_academy_name_id, user_academy_diploma, user_academy_speciality_id, user_academy_started_time, user_academy_end_time, user_academy_type_of_training, user_academy_graduation_degree, user_academy_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'userAcademyName' => array(self::BELONGS_TO, 'AcademyName', 'user_academy_name_id'),
			'userAcademyUser' => array(self::BELONGS_TO, 'User', 'user_academy_user_id'),
			'userAcademySpeciality' => array(self::BELONGS_TO, 'Speciality', 'user_academy_speciality_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_academy_id' => 'User Academy',
			'user_academy_name_id' => 'User Academy Name',
			'user_academy_diploma' => 'User Academy Diploma',
			'user_academy_speciality_id' => 'User Academy Speciality',
			'user_academy_started_time' => 'User Academy Started Time',
			'user_academy_end_time' => 'User Academy End Time',
			'user_academy_type_of_training' => 'User Academy Type Of Training',
			'user_academy_graduation_degree' => 'User Academy Graduation Degree',
			'user_academy_user_id' => 'User Academy User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_academy_id',$this->user_academy_id);
		$criteria->compare('user_academy_name_id',$this->user_academy_name_id);
		$criteria->compare('user_academy_diploma',$this->user_academy_diploma,true);
		$criteria->compare('user_academy_speciality_id',$this->user_academy_speciality_id);
		$criteria->compare('user_academy_started_time',$this->user_academy_started_time,true);
		$criteria->compare('user_academy_end_time',$this->user_academy_end_time,true);
		$criteria->compare('user_academy_type_of_training',$this->user_academy_type_of_training,true);
		$criteria->compare('user_academy_graduation_degree',$this->user_academy_graduation_degree,true);
		$criteria->compare('user_academy_user_id',$this->user_academy_user_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	
	//set knowledge
	public function getKnowledge()
	{
		return array(
			'Trung học'=>'Trung học',
			'Trung cấp'=>'Trung cấp',
		    'Cao đẳng'=>'Cao đẳng',
			'Cử nhân'=>'Cử nhân',
			'Kỹ sư'=>'Kỹ sư',
			'Thạc sĩ'=>'Thạc sĩ',
			'Tiến sĩ'=>'Dược sĩ',
			'Bác sĩ'=>'Bác sĩ',
			'Khác'=>'Khác'
			
		);
	}
	//set graduation degree
	public function getDegree()
	{
		return array(
			'Xuất sắc'=>'Xuất sắc',
			'Giỏi'=>'Giỏi',
			'Khá'=>'Khá',
			'Trung bình-Khá'=>'Trung bình-Khá',
			'Trung bình'=>'Trung bình'
		);
	}
	//set type of training
	public function getTypeTraining()
	{
		return array(
			'Chính qui'=>'Chính qui',
			'Tại chức'=>'Tại chức',
			'Chuyên tu'=>'Chuyên tu'
		);
	}      
}